import z from "zod";
import {
  ENUM_MessageCodeTemplate,
  buildMessageCode,
  valid_base_string,
  valid_base_number,
  valid_base_enum,
  valid_base_array,
  valid_id,
  valid_name,
  valid_price,
  valid_phone,
  valid_ratio,
  valid_desc,
} from "./core/index";

/** 预约人类型 */
export enum ENUM_ReservationType {
  /** 散客 */
  GUEST = 0,
  /** 会员 */
  MEMBER = 1,
}

/** 预约服务方式 */
export enum ENUM_ReservationServiceType {
  /** 到店 */
  IN = 0 as number,
  /** 上门 */
  OUT = 1 as number,
}

/** 预约重要性 */
export enum ENUM_ReservationPriority {
  /** 一般 */
  NORMAL = 0,
  /** 重要 */
  IMPORTANT = 1,
  /** 紧急 */
  URGENT = 2,
}

/** 预约状态 */
export enum ENUM_ReservationStatus {
  /** 注册登记 */
  REGISTRATION = 0,
  /** 开始服务 - 到店/上门 */
  START = 1,
  /** 完成服务 */
  COMPLETE = 2,
  /** 取消/撤销 */
  CANCEL = 3,
  /** 过期 */
  EXPIRED = 4,
}
const reservationDateTime = valid_base_string("预约时段").min(1, {
  message: buildMessageCode(ENUM_MessageCodeTemplate.empaty, "预约时段"),
});
const phone = valid_phone();
const name = valid_name("预约人姓名");
const serviceType = valid_base_enum(ENUM_ReservationServiceType, "服务方式");
const priority = valid_base_enum(ENUM_ReservationPriority, "重要性");
const products = valid_base_array(
  z.object({
    name: valid_name("产品名称"),
    price: valid_price("产品价格").default(0),
    actualPrice: valid_price("产品实价").default(0),
    quantity: valid_base_number("产品数量")
      .min(1, buildMessageCode(ENUM_MessageCodeTemplate.min, "产品数量"))
      .default(1),
  }),
  "商品列表"
).default([]);
const employee = valid_name("员工");
const deposit = valid_price("定金").default(0);
const desc = valid_desc();

// export const newReservationValid = z.object(ReservationValidObject);
export const newReservationValid = z.object({
  reservationDateTime,
  phone,
  name,
  serviceType,
  priority,
  products,
  employee,
  deposit,
  desc,
});

export interface IReqCreateReservation
  extends z.infer<typeof newReservationValid> {}
